#ifndef _ASYNCKET_H_
#define _ASYNCKET_H_

#include <WinSock2.h>

#define SOCKET_ADDR_SIZE	(sizeof(SOCKADDR_STORAGE) + 16)

class Asyncket;

typedef void (*ASYNCKET_CALLBACK)(OVERLAPPED * pOverlapped);

struct ASYNCKET_CONTEXT
{
	OVERLAPPED Overlapped;
	WSABUF WSABuf;
	Asyncket * pSender;
	ASYNCKET_CALLBACK Callback;
	void * pData;
};

struct ASYNCKET_ACCEPT_CONTEXT
{
	ASYNCKET_CONTEXT Context;
	BYTE SockAddrs[SOCKET_ADDR_SIZE * 2];
	Asyncket * Accept;
};

class Asyncket
{
public:
	Asyncket();
	~Asyncket();

public:
	SOCKET Object();

public:
	void Bind(struct sockaddr * addr, size_t addrlen);
	void Listen(int backlog);
	void Accept(ASYNCKET_CALLBACK callback, void * data);
	void Connect(struct sockaddr * addr, size_t addrlen, ASYNCKET_CALLBACK callback, void * data);
	void Disconnect(bool reuse, ASYNCKET_CALLBACK callback, void * data);
	void Recv(void * buf, ULONG len, ASYNCKET_CALLBACK callback, void * data);
	void Send(void * buf, ULONG len, ASYNCKET_CALLBACK callback, void * data);

private:
	SOCKET _s;

};

#endif // !_ASYNCKET_H_
